package com.ibm.risk.irmp.common.auth.oauth2.welink;

import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.GenericFilterBean;

import java.io.IOException;

@Component
@Order(5)
@Slf4j
public class WeLinkNologFilter extends GenericFilterBean {

    public static final String LOGIN_NOLOG_URI = "/login-nolog";
    @Autowired WelinkNologProcessor nologProcessor;
    @Override
    public void doFilter(ServletRequest request1, ServletResponse response1, FilterChain chain) throws IOException, ServletException {
        log.debug("no-log filtering...");
        HttpServletRequest request = (HttpServletRequest) request1;
        if (request.getRequestURI().endsWith(LOGIN_NOLOG_URI)) {
            HttpServletResponse response = (HttpServletResponse) response1;
            nologProcessor.processNolog(request, response);
        }
        chain.doFilter(request1, response1);
    }



}
